﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using Microsoft.Reporting.WebForms;

public class Utilitaria
{
    #region " Relatório "

    public static string ExportReport(ReportViewer rpv, string tipo)
    {
        Warning[] warnings;
        string[] streamids;
        string mimeType;
        string encoding;
        string filepath;
        string filename;
        string filenameExtension;
        Byte[] bytes;

        bytes = rpv.LocalReport.Render(tipo, null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);

        filename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Ticks.ToString();

        if (tipo == "PDF")
        {
            filename += ".pdf";
        }
        else
        {
            filename += ".xls";
        }

        filepath = HttpContext.Current.Server.MapPath("") + @"\admin\relatorios\" + filename;

        using (FileStream fs = new FileStream(filepath, FileMode.Create))
        {
            fs.Write(bytes, 0, bytes.Length);
        }

        return filename;
    }

    public static Byte[] ExportReportSemSalvar(ReportViewer rpv, string tipo)
    {
        Warning[] warnings;
        string[] streamids;
        string mimeType;
        string encoding;
        string filenameExtension;

        return rpv.LocalReport.Render(tipo, null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);
    }

    #endregion
}